package com.example.demo.dto.user.reg;

import org.springframework.util.StringUtils;

public class PRegDto {
    private String username;
    private String password;
    private String gender;
    private String student_array;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getStudent_array() {
        return student_array;
    }

    public void setStudent_array(String student_array) {
        this.student_array = student_array;
    }

    // 参数校验
    public String CheckOut(){
        if(!StringUtils.hasLength(this.username)){
            return "姓名不得为空";
        }
        if(!StringUtils.hasLength(this.password)){
            return "密码不得为空";
        }
        if(this.password.length() < 3 || this.password.length() >12){
            return "密码长度有误";
        }
        if(!StringUtils.hasLength(this.gender)){
            return "性别不得为空";
        }
        if(!(this.getGender().equals("男") || this.getGender().equals("女"))){
            return "性别填写有误";
        }
        if(!StringUtils.hasLength(this.student_array)){
            return "至少要关联一个学生学号";
        }

        String[] res = this.getStudent_array().split(",");
        for (String id: res) {
            if(!id.matches("\\d+")){
                return "关联的学生学号填写有误";
            }
        }
        return "";
    }
}
